<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Repository\RepositoryInterface\BargainInterface;
use Illuminate\Http\Request;

class BargainController extends Controller
{
    protected $bargain;

    public function __construct(BargainInterface $bargain){
        $this->bargain = $bargain;
    }

    /**
     * hsx
     * 砍价列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function bargainList(Request $request){
        try {

            $size = $request->get('pageSize');

            return $this->bargain->bargainList($size);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * hsx
     * 确认砍价商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function confirmBargain(Request $request){
        try {

            $id = $request->get('id');

            $uid = $request->uid;

            return $this->bargain->confirmBargain($id,$uid);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * hsx
     * 添加用户砍价商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addStoreBargain(Request $request){
        try {

            $post = $request->post();

            $uid = $request->uid;

            return $this->bargain->addStoreBargain($post,$uid);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }


    /**
     * hsx
     * 用户砍价商品详情
     * @return \Illuminate\Http\JsonResponse
     */
    public function bargainDetails(Request $request){
        try {

            $uid = $request->uid;

            return $this->bargain->bargainDetails($uid);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * hsx
     * 用户砍价
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function bargainInvite(Request $request){
        try {

            $id = $request->get('id');

            $uid = $request->uid;

            return $this->bargain->bargainInvite($id,$uid);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }


    /**
     * hsx
     * 商品详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function goodsDetails(Request $request){
        try {

            $id = $request->get('id');

            return $this->bargain->goodsDetails($id);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }
}
